Skip to content

feat(core): use native structured output for JSON stages - #413

Merged
parse merged 2 commits into
mainfrom
feat/structured-ai-output
Nov 18, 2026
Merged

parse merged 2 commits into
mainfrom
feat/structured-ai-output

Conversation

@parse

@parse parse commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #412.

What changed

  • Native structured output for the JSON stages (component selection, dependency scan, drift analysis), checked against each provider's docs:
    • Anthropic: output_config.format json_schema. A forced tool call was rejected because it returns 400 on Opus 5.5, Sonnet 5.5 and the Fable/Mythos 5.x models.
    • OpenAI: strict text.format json_schema; nullable objects and arrays use anyOf with {type: 'null'}, primitives use type arrays.
    • Gemini: responseMimeType: 'application/json' plus responseJsonSchema.
  • Schemas: generated from the existing Zod schemas (z.toJSONSchema, input side), sanitised recursively to keywords every provider accepts. Unrepresentable Zod types fail at module load. A test keeps the Anthropic schemas within its documented limits (24 optional, 16 union parameters).
  • Repair: one retry with the Zod issues and the invalid reply (truncated), then StructuredOutputError from errors.ts. Truncation, refusals and API errors are not repaired.
  • Component selection: the answer is constrained to the candidate ids (a plain string checked in code above 100 candidates). An unusable answer or a provider 400 falls back to the default component; auth, rate-limit and timeout errors still propagate. The free-text matcher is removed.
  • Cleanup: one callModel(..., output?) per provider; PromptBuilder.extractJson removed; OpenAI strict schema cached per spec.
  • Docs: ADR-014, ADR-002 note, configuration and AI providers pages list the model requirements.

Behaviour changes

  • Overridden fast or advanced models must support native structured output: OpenAI gpt-4o-2024-08-06 or later, a Gemini model with responseJsonSchema, any current Claude model.
  • Optional violation fields arrive as undefined instead of null.

Review follow-ups

  • Repair prompts list at most 20 issues of 200 characters each.

Checks

Check Result
check:ci pass
knip pass
Tests 1311 core + 10 cli pass
Live provider calls not run (no API keys here); request shapes verified against provider docs and mocked SDK clients

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 936e469b-5f80-4f9f-bacc-c032952d88a7
Commits

Reviewing files that changed from the base of the PR and between 38d4961 and 44b0e92.

Files selected for processing: 25

  • packages/core/src/analysis/__tests__/prompt-builder.test.ts
  • packages/core/src/analysis/prompt-builder.ts
  • packages/core/src/analysis/prompts/component-selection.md
  • packages/core/src/analysis/prompts/dependency-extraction.md
  • packages/core/src/analysis/prompts/drift-analysis.md
  • packages/core/src/errors.ts
  • packages/core/src/providers/__tests__/match-component-id.test.ts
  • packages/core/src/providers/__tests__/structured-output.test.ts
  • packages/core/src/providers/anthropic/__tests__/provider.test.ts
  • packages/core/src/providers/anthropic/__tests__/structured-output.test.ts
  • packages/core/src/providers/anthropic/provider.ts
  • packages/core/src/providers/base-provider.ts
  • packages/core/src/providers/gemini/__tests__/provider.test.ts
  • packages/core/src/providers/gemini/__tests__/structured-output.test.ts
  • packages/core/src/providers/gemini/provider.ts
  • packages/core/src/providers/openai/__tests__/provider.test.ts
  • packages/core/src/providers/openai/__tests__/structured-output.test.ts
  • packages/core/src/providers/openai/provider.ts
  • packages/core/src/providers/structured-output.ts
  • packages/core/src/utils/validation.ts
  • packages/web/src/content/docs/docs/contributing/adrs/002-provider-agnostic-ai-interface.md
  • packages/web/src/content/docs/docs/contributing/adrs/014-native-structured-ai-output.md
  • packages/web/src/content/docs/docs/contributing/adrs/index.md
  • packages/web/src/content/docs/docs/reference/ai-providers.md
  • packages/web/src/content/docs/docs/reference/configuration.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@parse
parse added this pull request to stack #414 November 17, 2026 17:21
@parse
parse force-pushed the feat/structured-ai-output branch from 84d3f4b to 53ab3f5 Compare November 17, 2026 17:49
@parse
parse marked this pull request as ready for review November 17, 2026 17:49
@parse
parse requested a review from a team as a code owner November 17, 2026 17:49
@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

The JSON analysis stages now use each AI provider’s native structured output, with shared Zod checks and one repair attempt.

  • Analysis stages now ask AI providers for schema-shaped JSON.
  • Local change scans no longer depend on repository Git settings.
  • Repository links resolve across hosts without relying on Git settings.

No new actionable issues found. Tests and live provider calls were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Analysis stage] --> B[Build prompt and schema]
  B --> C[Provider native structured output]
  C --> D[Parse JSON and check with Zod]
  D -->|Valid| E[Return result]
  D -->|Invalid| F[One bounded repair request]
  F --> G[Parse and check again]
  G -->|Valid| E
  G -->|Invalid| H[Stage error or component fallback]
Loading

Reviews (5) · Last reviewed commit: "fix(core): cap the issue list in structu..." · Reviewed by Greptile

@parse
parse force-pushed the feat/structured-ai-output branch 6 times, most recently from a4b3bb8 to 22dc2cd Compare November 18, 2026 07:24
Base automatically changed from fix/git-and-repo-url-parsing to main November 18, 2026 07:26
- Anthropic output_config.format, OpenAI strict json_schema (anyOf with
  null for nullable objects and arrays), Gemini responseJsonSchema
- JSON Schema generated from the Zod schemas and sanitised to keywords
  every provider accepts; unrepresentable types fail at load
- One repair retry with the Zod issues and the invalid reply, then
  StructuredOutputError; truncation and refusals are not repaired
- Component selection constrained to candidate ids, falling back to the
  default component on an unusable answer or a rejected request
- ADR-014, ADR-002 note, model requirements in the docs
Limit echoed validation issues to 20, each truncated to 200 chars, with an
"... and N more issues" line, so a large invalid response cannot blow up the
repair request.
@parse
parse force-pushed the feat/structured-ai-output branch from 22dc2cd to 44b0e92 Compare November 18, 2026 07:26
@parse
parse merged commit b3a34dc into main Nov 18, 2026
10 checks passed
@parse
parse deleted the feat/structured-ai-output branch November 18, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant